<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    let arr = [
        {
            id: 1,
            name: '张三',
            age: 21,
            workInfo: {
                addr: '北京市XXXXX',
                salary: 10000,
                year: 2
            }
        },
        {
            id: 2,
            name: '李四',
            age: 31,
            workInfo: {
                addr: '上海市XXXXX',
                salary: 200000,
                year: 3
            }
        },
        {
            id: 2,
            name: '王五',
            age: 11,
            workInfo: {
                addr: '天津市XXXXX',
                salary: 900000,
                year: 10
            }
        }
    ]
    // arr.sort((item1,item2)=>item1.age-item2.age)
    // arr.sort((item1,item2)=>item2.age-item1.age)
    // arr.sort((item1,item2)=>item2.workInfo.salary-item1.workInfo.salary)
    arr.sort((item1,item2)=>item1.workInfo.salary-item2.workInfo.salary)
    console.log('arr:',arr)
</script>
</body>
</html>
